package sql.show.demo;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListviewAdapter extends BaseAdapter {
	Context mContext;
	ArrayList<ProductList> mProductList;

	public ListviewAdapter(Context pContext, ArrayList<ProductList> pProductList) {
		mContext = pContext;
		mProductList = pProductList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mProductList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mProductList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			LayoutInflater ltInflate = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			viewHolder = new ViewHolder();
			convertView = ltInflate.inflate(R.layout.listview_custom, null);
			viewHolder.txtIdProduct = (TextView) convertView
					.findViewById(R.id.txtdisplaypid);
			viewHolder.txtNameProduct = (TextView) convertView
					.findViewById(R.id.txtdisplaypname);
			viewHolder.txtPriceProduct = (TextView) convertView
					.findViewById(R.id.txtdisplaypprice);
			convertView.setTag(viewHolder);

		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.txtIdProduct.setText(mProductList.get(position)
				.getIdProduct());
		viewHolder.txtNameProduct.setText(mProductList.get(position)
				.getNameProduct());
		viewHolder.txtPriceProduct.setText(mProductList.get(position)
				.getPriceProduct());
		return convertView;
	}

	private class ViewHolder {
		TextView txtIdProduct;
		TextView txtNameProduct;
		TextView txtPriceProduct;

	}

}
